<template>
  <VBaseDialog
    @close="handleClose"
    @save="save"
    title="修改"
    :loading="loading"
    width="950"
    destroy-on-close
  >
    <template #content>
      <el-form
        label-position="top"
        ref="formRef"
        :model="formValues"
        :rules="rules"
      >
        <div class="my-[16px]">
          配货单号/FBAID: &nbsp;&nbsp; {{ formValues?.fba_ids_str || "-" }}
        </div>
        <div class="grid grid-cols-3 gap-x-3">
          <el-form-item label="物流提货日期">
            <el-date-picker
              v-model="formValues.delivery_take_time"
              type="date"
              placeholder="请选择"
              value-format="YYYY-MM-DD"
              class="w-full"
            />
          </el-form-item>
          <el-form-item label="附加费">
            <el-input-number
              v-model="formValues.additional_freight"
              :controls="false"
              :precision="4"
              class="w-full"
            />
          </el-form-item>
          <el-form-item label="税号">
            <el-input v-model="formValues.tax_no" />
          </el-form-item>
          <el-form-item label="仓库计费重">
            <el-input-number
              v-model="formValues.charge_weight"
              :controls="false"
              :precision="4"
              class="w-full"
            />
          </el-form-item>
          <el-form-item label="仓库体积">
            <el-input-number
              v-model="formValues.volume"
              :precision="4"
              :controls="false"
              class="w-full"
            />
          </el-form-item>
          <el-form-item label="物流计费重">
            <el-input-number
              v-model="formValues.logistics_charge_weight"
              :controls="false"
              :precision="4"
              class="w-full"
            />
          </el-form-item>
          <el-form-item label="运费">
            <el-input-number
              v-model="formValues.freight"
              :controls="false"
              :precision="4"
              class="w-full"
            />
          </el-form-item>
          <el-form-item label="单价">
            <el-input-number
              v-model="formValues.price"
              :controls="false"
              :precision="4"
              class="w-full"
            />
          </el-form-item>
          <el-form-item label="国内运费">
            <el-input-number
              v-model="formValues.domestic_freight"
              :controls="false"
              :precision="4"
              class="w-full"
            />
          </el-form-item>
          <el-form-item label="杂费">
            <el-input-number
              v-model="formValues.incidental_freight"
              :controls="false"
              :precision="4"
              class="w-full"
            />
          </el-form-item>
          <el-form-item label="报关费">
            <el-input-number
              v-model="formValues.customs_clearance_freight"
              :controls="false"
              :precision="4"
              class="w-full"
            />
          </el-form-item>
          <el-form-item label="开票税额">
            <el-input-number
              v-model="formValues.invoice_tax"
              :controls="false"
              :precision="4"
              class="w-full"
            />
          </el-form-item>
          <el-form-item label="续页费">
            <el-input-number
              v-model="formValues.renewal_freight"
              :controls="false"
              :precision="4"
              class="w-full"
            />
          </el-form-item>
          <el-form-item label="查验费">
            <el-input-number
              v-model="formValues.inspection_freight"
              :controls="false"
              :precision="4"
              class="w-full"
            />
          </el-form-item>
          <el-form-item label="清关费">
            <el-input-number
              v-model="formValues.clearance_freight"
              :controls="false"
              :precision="4"
              class="w-full"
            />
          </el-form-item>
          <el-form-item label="运费赔偿、时效、丢件">
            <el-input-number
              v-model="formValues.freight_indemnity"
              :controls="false"
              :precision="4"
              class="w-full"
            />
          </el-form-item>
          <el-form-item label="超品名">
            <el-input v-model="formValues.superbrand" />
          </el-form-item>
          <el-form-item label="应付物流总金额RMB">
            <el-input-number
              v-model="formValues.logistics_total_amount_cny"
              :controls="false"
              :precision="4"
              class="w-full"
            />
          </el-form-item>
          <el-form-item label="税金">
            <el-input-number
              v-model="formValues.tax_freight"
              :controls="false"
              :precision="4"
              class="w-full"
            />
          </el-form-item>
        </div>
      </el-form>
    </template>
  </VBaseDialog>
</template>
<script setup lang="jsx">
import { ElMessage } from "element-plus";
import { invoiceRegisterDetail, invoiceRegisterUpdate } from "../../api.js";
const props = defineProps({
  id: { type: [String, Number], default: "" },
  type: { type: [String, Number], default: "" },
  option: { type: Object, default: () => {} },
});
const { option } = toRefs(props);
const emit = defineEmits(["update:modelValue", "close", "refresh"]);
const loading = ref(false);
const formValues = ref({});
const formRef = ref();
watch(
  () => props.id,
  (val) => {
    if (val) {
      nextTick(() => {
        getDetail(val);
      });
    }
  }
);
const getDetail = async (id) => {
  const { data } = await invoiceRegisterDetail({ id });
  formValues.value = data || {};
};
const save = async () => {
  const { code, message, data } = await invoiceRegisterUpdate(formValues.value);
  if (code != 200) return ElMessage.error(message);
  ElMessage.success("修改成功!");
  handleClose(true);
};
const handleClose = async (refresh) => {
  formValues.value = {};
  formRef.value.resetFields();
  emit("update:modelValue", false);
  emit("close");
  if (refresh) emit("refresh");
};
</script>
<style lang="scss" scoped></style>
